const fs = require('fs');
const readStream = fs.createReadStream('data.txt');
readStream.setEncoding('utf-8');
var writer = fs.createWriteStream('dataWrite.txt');

var data = '';
var cnt = 0;

var start = new Date();

// readStream.on('data', chunk => {
//     data += chunk;
//     cnt++;
//     console.log('第' + cnt + '次得到数据块， 共' + chunk.length + '字节；');
//     // writer.write(chunk, 'utf-8');

//     // console.log(data);
// });

// readStream.on('close', ()=>{

//     writer.write(data, 'utf-8');
//     writer.end();
// });

writer.on('finish', () => {
    var endTime = new Date();
    var diff = (endTime - start);
    console.log('写入完毕！耗时：' + diff);
});

readStream.pipe(writer);

console.log('程序执行完毕！');